const api = require('../../utils/api.js');
const app = getApp();

Page({
  data: {
    abnorData: {
      imgSrc: app.imgUrl + 'abnor-19.png',
      text: '暂无物流信息',
    },
    imgUrl: app.imgUrl,
    isShowLoading: false,
  },

  onLoad(options) {
    let opts = options || {};
    app.pageOnLoad(this);
    this.setData({ opts });
    this.loadData(opts);
  },

  loadData(options) {
    let that = this;
    let { type: _type, id: order_id, express_id } = options;
    let url;
    let args = {
      order_id,
    };
    if (_type === 'goods') {
      url = api.order.express_detail;
      args.express_id = express_id;
    } else if (_type === 'pt') {
      url = api.group.order.express_detail;
    } else if (_type === 'miaosha') {
      url = api.miaosha.express_detail;
    }
    wx.showLoading({
      title: '正在加载',
    });
    app.ws_micro_shoprequest({
      url,
      data: args,
      success: function(res) {
        wx.hideLoading();
        if (res.code === 0) {
          that.setData({
            data: res.data,
            list: res.data.list || [],
          });
        }
        if (res.code === 1) {
          wx.showModal({
            title: '提示',
            content: res.msg,
            showCancel: false,
            success: function(e) {
              if (e.confirm) {
                wx.navigateBack();
              }
            },
          });
        }
      },
      complete: () => {
        that.setData({
          isShowLoading: true,
        })
      }
    });
  },

  copyText(e) {
    let text = e.currentTarget.dataset.text;
    wx.setClipboardData({
      data: text,
      success: function() {
        wx.showToast({
          title: '已复制',
          icon: 'none',
        });
      },
    });
  },
});
